const JsonResult = require('@/utils/httpResponse.util')
const circleService = require('@/services/circle.service')

class CircleController {
  async findPage (req, response) {
    const { pageNo, pageSize, searchKeywords } = req.query
    try {
      const data = await circleService.findPage(pageNo, pageSize, searchKeywords)
      JsonResult.success({
        req,
        response,
        data,
        message: '查询成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '查询失败' })
    }
  }

  async deleteById (req, response) {
    const id = req.query.id
    try {
      const data = await circleService.delete(id)
      if (data?.errorMessage) {
        return JsonResult.fail({ req, response, message: data?.errorMessage })
      }
      JsonResult.success({
        req,
        response,
        data,
        message: '删除成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '删除失败' })
    }
  }
}

module.exports = new CircleController()
